/**
 * 
 */
package org.dailydev.mojo.birt.runner.commandline;

import org.apache.maven.plugin.MojoExecutionException;
import org.codehaus.plexus.util.cli.Commandline;
import org.codehaus.plexus.util.cli.Commandline.Argument;
import org.dailydev.mojo.birt.runner.HtmlTypesEnum;

/**
 * @author bosakrom
 * 
 */
public class HTMLRenderConfig implements IRenderConfig {

	private static final String ARGUMENT_NAME__ENCODING = "--encoding";
	private static final String ARGUMENT_NAME__HTML_TYPE = "--htmlType";

	/**
	 * Switch for HTML format to generate report as reportlet.
	 */
	private boolean htmlReportlet = false;

	/**
	 */
	private String encoding;

	/**
	 * 
	 */
	public HTMLRenderConfig() {
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @throws MojoExecutionException
	 */
	public void defineArguments(Commandline commandline) throws MojoExecutionException {
		defineHtmlTypeArgument(commandline);
		defineEncodingArgument(commandline);
	}

	/**
	 * 
	 */
	protected void defineEncodingArgument(Commandline commandline) {
		if (this.getEncoding() != null) {
			Argument encodingArg = commandline.createArgument();
			encodingArg.setValue(ARGUMENT_NAME__ENCODING);
			Argument encodingArgValue = commandline.createArgument();
			encodingArgValue.setValue(this.getEncoding());
		}
	}

	/**
	 * @throws MojoExecutionException
	 */
	protected void defineHtmlTypeArgument(Commandline commandline) throws MojoExecutionException {
		Argument htmlTypeArg = commandline.createArgument();
		htmlTypeArg.setValue(ARGUMENT_NAME__HTML_TYPE);
		Argument htmlTypeArgValue = commandline.createArgument();
		if (this.isHtmlReportlet()) {
			htmlTypeArgValue.setValue(HtmlTypesEnum.REPORTLET.getValue());
		} else {
			htmlTypeArgValue.setValue(HtmlTypesEnum.HTML.getValue());
		}
	}

	/**
	 * @return
	 */
	protected String getEncoding() {
		return this.encoding;
	}

	/**
	 * @return
	 */
	public boolean isHtmlReportlet() {
		return this.htmlReportlet;
	}

	/**
	 * @param encoding
	 */
	public void setEncoding(String encoding) {
		this.encoding = encoding;
	}

	/**
	 * @param htmlReportlet
	 */
	public void setHtmlReportlet(boolean htmlReportlet) {
		this.htmlReportlet = htmlReportlet;
	}
}
